package day3.demo9_lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Sell implements Runnable{
    int sum = 1000;
    Lock lo = new ReentrantLock();
    @Override
    public void run() {
        while (sum>0){
            try {
                lo.lock();
                if (sum <= 0) {
                    return;
                }
                System.out.println(Thread.currentThread().getName() + "卖出第" + sum + "张票");
                sum--;
            }finally {
                lo.unlock();
            }
        }
    }
}
